#include <iostream>
#include <string>
#include <memory>
#include "Reactor.hpp"
#include "Socket.hpp"
#include "Connection.hpp"
#include "Accepter.hpp"
using namespace std;
using namespace Net_Work;
const int default_backlog = 32;


int main(int argc, char* args[]) {
    if (argc != 2) {
        cout << "Usage:\n\r" << args[0] << " local_port\n" << endl;
        return 0;
    }
    uint16_t port = stoi(args[1]);
    // 创建一个监听套接字
    unique_ptr<Socket> listensocket(new TcpSocket(port));
    listensocket->BuildListenSocketMethod(port, default_backlog);
    unique_ptr<Reactor> svr(new Reactor());
    // 创建一个监听connection
    Connection* listen_connection = ConnectionFactory::BuildListenConnection(listensocket->GetSockFd(), EPOLLIN | EPOLLET, svr.get(), Accepter::Accept);

    // 添加到svr的哈希表
    svr->AddConnection(listen_connection);

    // 开始派发事件
    svr->Dispatch();
    return 0;
}